<?php
/**
 * Created by PhpStorm.
 * User: Allan
 * Date: 2018/7/11
 * Time: 18:03
 */

namespace App\Http\Controllers;


use Illuminate\Http\Request;

class FormatCodeController extends Controller
{
    /**
     * @api {post} /formatCode/index 代码格式化
     * @apiName index
     * @apiGroup formatCode
     *
     * @apiParam {String} code 代码
     * @apiParam {String} space  空格
     * @apiSuccessExample {value} 成功返回:
     *     {
     *         "data": [
     *
     *         ],
     *         "code": 200,
     *         "msg": null
     *     }
     *
     */
    public function index(Request $request){
        $code = $request->input('code','');
        $space = $request->input('space','     ');
        $code = str_replace(array("\r", "\n", "\r\n"), '[回车]', $code);
        $codeArr = explode('[回车]',$code);
        $prefix = $space.'*'.$space;
        foreach ($codeArr as $key => $value){
            echo $prefix.$value.PHP_EOL;
        }
    }
}